<template>
	<view>
		<view class="top">
			<view class="video_tit">
				<view @click="change(1)" class="itemss " :class="params.type==1?'itemsselect':''">
					找合作
					<view class="xs" v-show="params.type==1"></view>
				</view>
				<view @click="change(2)" class="itemss" :class="params.type==2?'itemsselect':''">
					聊需求
					<view class="xs" v-show="params.type==2"></view>
				</view>
			</view>
		</view>

		<view class="text">
			<textarea v-model="params.content" placeholder="请输入"></textarea>
			<view class="" style="margin: 20rpx 20rpx 0rpx 0rpx">
				<ImageUpload :imgList='imgList' @change='changeImg'></ImageUpload>
			</view>
		</view>


		<view class="">
			<view class="item flex">
				<view class="t">
					<span style="color: red;">*</span>手机号：
				</view>
				<input v-model="params.mobile" type="number" maxlength="11" placeholder="填写后，对方可以选择与您通话沟通" />
			</view>

			<view class="item flex">
				<view class="t">
					微信号：
				</view>
				<input v-model="params.wechat" type="text" placeholder="填写后，对方可以选择与您微信沟通" />
			</view>
		</view>

		<view class="footer_kf">
			<view class="cont flex_jc_cent">
				<view class="btn" @click="handleCreateOrder">
					发布
				</view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import ImageUpload from '@/components/imageUpload/imageUpload.vue'
	import {
		reactive,
		ref
	} from 'vue';
	import {onLoad} from '@dcloudio/uni-app'
	import {
		addBusinessList,editBusinessList,detailBusinessList
	} from '@/common/http.api.js';
	
	
	onLoad((option)=>{
		if(option.id){
			params.id = option.id
			uni.setNavigationBarTitle({
				title:'修改商机'
			})
			detailBusinessList({id:option.id}).then(res=>{
				params.type = res.data.type
				params.content = res.data.content
				params.images = res.data.images
				params.mobile = res.data.mobile
				params.wechat = res.data.wechat
			
				imgList.value = res.data.images_obj
			})
		}
		
	})
	
	function change(i) {
		params.type = i
	}
	const params = reactive({
		id:'',
		type: 1,
		content: '',
		images: '',
		mobile: '',
		wechat: '',
	})
	const imgList = ref([])
	function changeImg(e){
		console.log(e);
		params.images = e.map(item=>{return item.fullurl}).join(',')
		imgList.value = e
	}
	function handleCreateOrder() {
		if (params.content == '') {
			uni.showToast({
				icon: 'none',
				title: '请输入文本'
			})
			return
		}
		if (params.mobile == '') {
			uni.showToast({
				icon: 'none',
				title: '请输入手机号'
			})
			return
		}
		if(params.id){
			editBusinessList(params).then(res=>{
				if (res.code == 1) {
					uni.showToast({
						icon: 'none',
						title: '已修改'
					})
					setTimeout(() => {
						uni.navigateBack({})
					}, 1000)
				}
			})
		}else{
			addBusinessList(params).then(res=>{
				if (res.code == 1) {
					uni.showToast({
						icon: 'none',
						title: '已发布'
					})
					setTimeout(() => {
						uni.navigateBack()
					}, 1000)
				}
			})
		}


	}
</script>

<style lang="scss">
	.k1 {
		text-align: center;
		margin: 120rpx auto;
		width: 360rpx;
		image {
			width: 360rpx;
			height: 360rpx;
		}
		.texts {
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #979797;
			margin-top: 10rpx;
		}
	}
	.top {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		align-items: center;
		padding: 0rpx 20rpx 0rpx 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		
		.video_tit {
			display: flex;
			justify-content: space-around;
			width: 710rpx;

			.itemss {
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #2F3245;
			}

			.itemsselect {
				font-family: PingFang SC, PingFang SC;
				font-weight: bold;
				font-size: 32rpx;
				color: #000000;
			}

			.xs {
				width: 32rpx;
				height: 6rpx;
				background: #0756FF;
				border-radius: 4rpx 4rpx 4rpx 4rpx;
				margin: 6rpx auto 0rpx;
			}

		}
	}

	.text {
		width: 710rpx;
		background: #F7F8FC;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 0rpx auto;
		padding: 20rpx;
		box-sizing: border-box;

		textarea {
			width: 670rpx;
			font-size: 28rpx;
			box-sizing: border-box;
			max-height: 400rpx;
		}
	}

	.item {
		width: 710rpx;
		height: 100rpx;
		background: #F7F8FC;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		margin: 20rpx auto;
		font-size: 28rpx;
		padding: 0rpx 30rpx;
		box-sizing: border-box;
		input{
			flex: 1;
		}

		.t {
			color: #000000;
		}
	}

	.footer_kf {
		width: 750rpx;
		height: 120rpx;
		background: #FFFFFF;
		box-shadow: 0rpx 1px 10rpx 0rpx rgba(0, 0, 0, 0.2);
		position: fixed;
		bottom: 0%;
		padding-bottom: constant(safe-area-inset-bottom);
		padding-bottom: env(safe-area-inset-bottom);

		.cont {
			padding: 10rpx 30rpx 10rpx 40rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			height: 120rpx;
			color: #000000;

			.kf {
				width: 60rpx;
				height: 100rpx;
				position: relative;

				image {
					width: 48rpx;
					height: 48rpx;
				}

				font-family: PingFang SC,
				PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #545454;

				.adsbtn {
					width: 100rpx;
					height: 100rpx;
					position: absolute;
					top: 0%;
					opacity: 0;
				}
			}

			.btn {
				width: 600rpx;
				height: 80rpx;
				border-radius: 40rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				line-height: 80rpx;
				text-align: center;
				background: #0756FF;
				color: #fff;
			}
		}
	}
</style>